home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 21 / CU Amiga Magazine's Super CD-ROM 21 (1998)(EMAP Images)(GB)[!][issue 1998-04].iso / CUCD / Programming / dclistview / dclistview.e < prev    next >
Text File  |  1998-01-17  |  6KB  |  173 lines

  1. OPT MODULE, PREPROCESS
  2.  
  3. MODULE 'gadtools', 'libraries/gadtools', 'devices/inputevent',
  4.        'intuition/gadgetclass', 'intuition/intuition', 'utility/tagitem',
  5.        'tools/EasyGUI', 'tools/textlen', 'tools/ctype', 'exec/nodes',
  6.        'exec/lists', 'utility'
  7.  
  8. ->define DCLIST to make EasyGUI's gadget list more readable!
  9. EXPORT CONST DCLIST=PLUGIN
  10.  
  11. EXPORT ENUM DCLV_LABEL=$FF000001,            -> [I..]
  12.   DCLV_RELX,                                 -> [I..]
  13.   DCLV_RELY,                                 -> [I..]
  14.   DCLV_LIST,                                 -> [ISG]
  15.   DCLV_CURRENT,                              -> [ISG]
  16.   DCLV_CLICK,                                -> [..G]
  17.   DCLV_TOP,                                  -> [ISG]
  18.   DCLV_DISABLED                              -> [ISG]
  19.  
  20. EXPORT OBJECT dclistview OF plugin PRIVATE
  21.   disabled
  22.   current
  23.   top
  24.   clicked
  25.   listview:PTR TO gadget
  26.   label
  27.   labelhi
  28.   relx, rely
  29.   execlist
  30.   maxnode
  31.   key
  32.   second1, micros1
  33.   second2, micros2
  34.   vers
  35. ENDOBJECT
  36.  
  37. PROC dclistview(tags:PTR TO tagitem) OF dclistview
  38. DEF key,label
  39.   IF utilitybase
  40.     self.label:=      GetTagData(DCLV_LABEL,     NIL, tags)
  41.     self.relx :=  Max(GetTagData(DCLV_RELX,        5, tags), 5)
  42.     self.rely :=  Max(GetTagData(DCLV_RELY,        5, tags), 2)
  43.     self.execlist:=   GetTagData(DCLV_LIST,      NIL, tags)
  44.     self.maxnode:=    max_node(self.execlist)
  45.     self.current:=Max(GetTagData(DCLV_CURRENT,   NIL, tags), -1)
  46.     self.top:=    Max(GetTagData(DCLV_TOP,       NIL, tags),0)
  47.     self.disabled:=   GetTagData(DCLV_DISABLED,FALSE, tags)
  48.     IF label:=self.label
  49.       self.key:= IF key:=InStr(label, '_') THEN tolower(label[key+1]) ELSE NIL
  50.       self.key:= IF isalpha(self.key) THEN self.key ELSE NIL
  51.     ENDIF
  52.     self.second1:=NIL
  53.     self.second2:=NIL
  54.     self.micros1:=NIL
  55.     self.micros2:=NIL
  56.     self.vers:=KickVersion(39)
  57.   ELSE
  58.     Raise("util")
  59.   ENDIF
  60. ENDPROC
  61.  
  62. PROC end() OF dclistview IS EMPTY
  63.  
  64. PROC min_size(ta,fh) OF dclistview
  65.   self.labelhi:=IF self.label THEN fh+5 ELSE 0
  66. ENDPROC Max(textlen_key(self.label,ta,self.key),self.relx*fh), self.rely*fh+self.labelhi+5
  67.  
  68. PROC will_resize() OF dclistview IS (RESIZEX OR RESIZEY)
  69.  
  70. PROC gtrender(gl,vis,ta,x,y,xs,ys,w) OF dclistview HANDLE
  71.   self.listview:=CreateGadgetA(LISTVIEW_KIND,gl,
  72.                  [x,y+self.labelhi,xs,ys-self.labelhi,self.label,
  73.                      ta,0,0,vis,NIL]:newgadget,
  74.                  [GTLV_LABELS, self.execlist,
  75.                   GA_DISABLED, self.disabled,
  76.                   IF self.key THEN GT_UNDERSCORE ELSE TAG_IGNORE, "_",
  77.                   GTLV_SHOWSELECTED, NIL,
  78.                   GTLV_SELECTED, self.current,
  79.                   GTLV_TOP, self.top,
  80.                   TAG_DONE])
  81.   IF self.listview=NIL THEN Raise("dclv")
  82. EXCEPT DO
  83.   ReThrow()
  84. ENDPROC self.listview
  85.  
  86. PROC message_test(imsg:PTR TO intuimessage,win:PTR TO window) OF dclistview
  87. DEF islist=FALSE
  88. IF ((imsg.class=IDCMP_VANILLAKEY) AND Not(self.disabled)) THEN RETURN (self.key=tolower(imsg.code))
  89. IF (imsg.class=IDCMP_GADGETUP)
  90.   IF islist:= (imsg.iaddress=self.listview)
  91.     self.second2:=imsg.seconds
  92.     self.micros2:=imsg.micros
  93.   ENDIF
  94. ENDIF
  95. ENDPROC islist
  96.  
  97. PROC message_action(class,qual,code,win:PTR TO window) OF dclistview
  98. DEF newcurrent
  99. SELECT class
  100.   CASE IDCMP_VANILLAKEY
  101.     IF (qual AND (IEQUALIFIER_LSHIFT OR IEQUALIFIER_RSHIFT))
  102.       newcurrent:=Max(self.current-1, 0)
  103.     ELSE
  104.       newcurrent:=Min(self.current+1, self.maxnode)
  105.     ENDIF
  106.     IF newcurrent=self.current THEN RETURN FALSE ELSE self.current:=newcurrent
  107.     self.set(DCLV_CURRENT, self.current)
  108.   CASE IDCMP_GADGETUP
  109.     IF code=self.current
  110.       self.clicked:=(IF self.clicked THEN FALSE ELSE DoubleClick(self.second1,self.micros1,self.second2,self.micros2))
  111.     ELSE
  112.       self.current:=code
  113.     ENDIF
  114. ENDSELECT
  115.   self.second1:=self.second2
  116.   self.micros1:=self.micros2
  117.   self.second2:=NIL
  118.   self.micros2:=NIL
  119. ENDPROC TRUE
  120.  
  121. PROC set(attr, val) OF dclistview
  122.   SELECT attr
  123.     CASE DCLV_DISABLED
  124.       IF self.vers
  125.         IF self.disabled<>val
  126.           self.disabled:=val
  127.           IF visible(self) THEN
  128.             Gt_SetGadgetAttrsA(self.listview,self.gh.wnd,NIL,[GA_DISABLED,self.disabled,TAG_DONE])
  129.           self.clicked:=FALSE
  130.         ENDIF
  131.       ENDIF
  132.     CASE DCLV_LIST
  133.       self.maxnode:=max_node(val)
  134.       IF visible(self) THEN
  135.         Gt_SetGadgetAttrsA(self.listview, self.gh.wnd, NIL, [GTLV_LABELS, val, TAG_DONE])
  136.       self.execlist:=val
  137.       self.clicked:=FALSE
  138.     CASE DCLV_TOP
  139.       self.top:=Bounds(val,0,self.maxnode)
  140.       IF visible(self) THEN
  141.         Gt_SetGadgetAttrsA(self.listview, self.gh.wnd, NIL, [GTLV_TOP, self.top, TAG_DONE])
  142.     CASE DCLV_CURRENT
  143.       self.current:= Bounds(val,-1,self.maxnode)
  144.       IF visible(self) THEN
  145.         Gt_SetGadgetAttrsA(self.listview, self.gh.wnd, NIL, [GTLV_SELECTED, self.current,
  146.                                                              IF self.vers THEN GTLV_MAKEVISIBLE ELSE GTLV_TOP, Max(val,0),
  147.                                                              TAG_DONE])
  148.       self.clicked:=FALSE
  149.       RETURN self.current
  150.   ENDSELECT
  151. ENDPROC
  152.  
  153. PROC get(attr) OF dclistview
  154.   SELECT attr
  155.     CASE DCLV_LIST;     RETURN self.execlist, TRUE
  156.     CASE DCLV_CURRENT;  RETURN self.current, TRUE
  157.     CASE DCLV_TOP;      RETURN self.top, TRUE
  158.     CASE DCLV_CLICK;    RETURN self.clicked, TRUE
  159.     CASE DCLV_DISABLED; RETURN self.disabled, TRUE
  160.   ENDSELECT
  161. ENDPROC -1, FALSE
  162.  
  163. PROC visible(self:PTR TO dclistview) IS (self.listview AND self.gh.wnd)
  164.  
  165. PROC max_node(list:PTR TO lh)
  166. DEF node:PTR TO ln, i=NIL
  167.   IF list>0
  168.     node:=list.head
  169.     WHILE node:=node.succ DO INC i
  170.   ENDIF
  171. ENDPROC i
  172.  
  173.